<html>

<head>
    <link rel="stylesheet" href="./css/style.css">
    <title>学生成绩管理系统</title>
    <script src="./js/jquery-3.7.1.min.js"></script>
    <script>
        function remove(ele) {
            let id = ele.parentElement.parentElement.children[0].innerText;
            console.log(id);
            window.location.href = "./dataServer/remove.php?id=" + id;
        }

        function updateDeta(ele) {
            let id = ele.parentElement.parentElement.children[0].innerText;
            console.log(id);
            window.location.href = "./update.php?id=" + id;
        }
    </script>
</head>

<body>
    <h1>
        学生成绩列表
    </h1>
    登录者:
    <?php
    // 启动session
    session_start();
    // 输出登陆者
    echo $_SESSION["username"];
    ?>
    <table border="1">
        <tr>
            <td>编号</td>
            <td>姓名</td>
            <td>年龄</td>
            <td>成绩</td>
            <td>操作</td>
        </tr>
        <?php
        // 引用数据库连接
        include_once("./dataServer/conServer.php");
        $sql = "select id,name,age,result FROM result";
        $rs = $conn->query($sql);
        // 执行sql
        if ($rs->num_rows > 0) {
            while ($row = $rs->fetch_assoc()) {
        ?>
                <tr>
                    <td><?php echo $row["id"]; ?></td>
                    <td><?php echo $row["name"]; ?></td>
                    <td><?php echo $row["age"]; ?></td>
                    <td><?php echo $row["result"]; ?></td>
                    <td>
                        <button onclick="updateDeta(this)">修改</button>
                        <button onclick="remove(this)">删除</button>
                    </td>
                </tr>
        <?php
            }
        }
        // 关闭数据库连接
        $conn->close();
        ?>
        <tr>
            <td colspan="2"><a href="./update.php"><button>添加</button></a></td>
        </tr>
    </table>
</body>

</html>